package org.acghub.mtdb.xmlgen.maker.bean;

import org.acghub.mtdb.common.Bean;
import org.acghub.mtdb.common.Config;
import org.acghub.mtdb.core.TBean;
import org.acghub.mtdb.util.StringUtil;
import org.acghub.mtdb.xmlgen.Maker;

import java.io.PrintStream;

public class BeanConstructorMaker extends Maker<Bean> {

    private final PrintStream ps;
    private final String prefix;

    public BeanConstructorMaker(Bean inner, Config config, PrintStream ps, String prefix) {
        super(inner, config);
        this.ps = ps;
        this.prefix = prefix;
    }

    private String getBaseClassName() {
        return TBean.class.getCanonicalName();
    }

    @Override
    public void make() throws Exception {
        ps.printf(prefix + "public %s(%s _xp_, String _vn_) {\n", this.inner().getName(), getBaseClassName());
        ps.println(StringUtil.concat(prefix, StringUtil.TAB) + "super(_xp_, _vn_);");
        ps.println(prefix + "}");
        ps.println();
        ps.println(StringUtil.TAB + "public " + this.inner().getName() + "() {");
        ps.println(StringUtil.tab(2) + "this(null, null);");
        ps.println(StringUtil.TAB + "}");
        ps.println();
    }
}
